home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / BIRTHSRC.ZIP / INTMISC.INC < prev    next >
Text File  |  1993-11-23  |  7KB  |  348 lines

  1. ;╔════════════════════════════════════════════════╗
  2. ;║  Name:Video_Sync_And_Keyboard_INT_Routines      ║
  3. ;║                                                ║
  4. ;║  Modified:23-Nov-93                   FB ║
  5. ;╚════════════════════════════════════════════════╝
  6. ;
  7. ;--------------------------------------------------------------
  8. ;
  9. ; SetINT8
  10. ;   -INT8handler
  11. ; RestoreINT8
  12. ;
  13. ; SetINT9
  14. ;   -INT9handler
  15. ; RestoreINT9
  16. ;
  17. ; DisableKbd
  18. ; EnableKbd
  19. ;
  20. ; WaitBorder
  21. ; GetRasterline
  22. ; WaitRasterline
  23. ;
  24. ;-----------------------------------------------------------------
  25.  
  26. frametime    dw ?
  27. oldINT8     dd ?
  28. oldINT9     dd ?
  29.  
  30. ;-----------------------------------------------------------------
  31. INT8handler PROC FAR
  32.  
  33.     ;timer interrupt
  34.     push    ax
  35.     push    dx
  36.  
  37.     mov    al,20h
  38.     out    20h,al
  39.  
  40.     mov    dx,3dah
  41. int8_1: in    al,dx
  42.     test    al,8
  43.     jz    int8_1       ; wait for VR
  44.        ;call waitborder
  45.  
  46.     mov    al,34h       ; pulse
  47.     out    43h,al
  48.     mov    al,byte ptr cs:[frametime]
  49.     out    40h,al
  50.     mov    al,byte ptr cs:[frametime+1]
  51.     out    40h,al
  52.  
  53.     ;NOTE: we are now in a VR!
  54.     ;if housekeeper takes relative long you might want to
  55.     ;move it to the beginning of the handler and adjust
  56.     ;the interrupt timing s.t. the prog gets interrupted
  57.     ;some additional scan lines before the VR.
  58.     sti
  59.     call    housekeeper
  60.     cli
  61.  
  62.     pop    dx
  63.     pop    ax
  64.     iret
  65. INT8handler ENDP
  66.  
  67. ;-----------------------------------------------------------------
  68. ; SetINT8 - Sets Timer Interrupt (8) - timer synchronized with VR
  69. ;    IN     : -
  70. ;   OUT     : -
  71. ;  Modified : ax,dx
  72. ;  Vars Used: oldINT8,frametime
  73.  
  74.  
  75. SetINT8 PROC NEAR
  76.     cli
  77.     ;set up timer int vector
  78.     push    es
  79.     xor    ax,ax
  80.     mov    es,ax
  81.     mov    ax,es:[8*4]
  82.     mov    word ptr cs:oldINT8[0],ax
  83.     mov    ax,es:[8*4+2]
  84.     mov    word ptr cs:oldINT8[2],ax
  85.     mov    ax,offset INT8handler
  86.     mov    es:[8*4],ax
  87.     mov    es:[8*4+2],cs
  88.     pop    es
  89.     sti
  90.  
  91.     ;find time it takes from VR to next VR
  92.     call    waitborder
  93.     ;set timer to max period 65536
  94.     mov    al,34h        ;pulse
  95.     out    43h,al
  96.     mov    al,0
  97.     out    40h,al
  98.     mov    al,0
  99.     out    40h,al
  100.  
  101.     call    waitborder
  102.     xor    al,al        ;latch present counter value
  103.     out    43h,al
  104.     in    al,40h        ;read LO
  105.     mov    ah,al
  106.     in    al,40h        ;read HI
  107.     xchg    al,ah
  108.  
  109.     ;counter counts down from 65536
  110.     ;to find time: (65536-HILO)=-HILO
  111.     neg    ax
  112.  
  113.     ;frametime = frametime-(frametime/128)
  114.     ;make sure we never miss the beginning of a VR
  115.     mov    dx,ax
  116.     shr    ax,7        ;7 works fine with short housekeeper
  117.     sub    dx,ax
  118.     mov    cs:frametime,dx     ;length of one frame
  119.  
  120.     ;set timer
  121.     call    waitborder
  122.     mov    al,34h        ;pulse
  123.     out    43h,al
  124.     mov    al,byte ptr cs:[frametime]
  125.     out    40h,al
  126.     mov    al,byte ptr cs:[frametime+1]
  127.     out    40h,al
  128.     ret
  129.  
  130. SetINT8 ENDP
  131.  
  132. ;-----------------------------------------------------------------
  133. ; RestoreINT8 - Restores Timer Interrupt (8)
  134. ;    IN     : -
  135. ;   OUT     : -
  136. ;  Modified : ax,dx
  137. ;  Vars Used: oldINT8
  138.  
  139.  
  140. RestoreINT8 PROC NEAR
  141.     cli
  142.     push    es
  143.     mov    ax,0
  144.     mov    es,ax
  145.     mov    ax,WORD PTR cs:oldINT8[0]
  146.     mov    dx,WORD PTR cs:oldINT8[2]
  147.     mov    es:[8*4],ax
  148.     mov    es:[8*4+2],dx
  149.     sti
  150.  
  151.     ; retore timer to old setting
  152.     mov    al,34h        ;pulse
  153.     out    43h,al
  154.     mov    al,0
  155.     out    40h,al
  156.     mov    al,0
  157.     out    40h,al
  158.     pop    es
  159.     ret
  160.  
  161. RestoreINT8 ENDP
  162.  
  163. ;-------------------------------------------------------------------
  164. ; DisableKbd - Disables Keyboard
  165. ;    IN     : -
  166. ;   OUT     : -
  167. ;  Modified : ax
  168. ;  Vars Used: -
  169.  
  170. DisableKbd PROC NEAR
  171.     in    al,21h
  172.     or    al,00000010b
  173.     out    21h,al
  174.     ret
  175. DisableKbd ENDP
  176.  
  177. ;-----------------------------------------------------------------
  178. ; EnablesKbd - Enables Keyboard
  179. ;    IN     : -
  180. ;   OUT     : -
  181. ;  Modified : ax
  182. ;  Vars Used: -
  183.  
  184. EnableKbd PROC NEAR
  185.     in    al,21h
  186.     and    al,11111101b
  187.     out    21h,al
  188.     ret
  189. EnableKbd ENDP
  190.  
  191. ;-----------------------------------------------------------------
  192.  
  193. INT9handler PROC FAR
  194.     push    ax
  195.         in      al,60h
  196.        ; cmp     al,01h      ; ESC
  197.        ; je     nokey
  198.     cmp    al,1ch        ; RETURN
  199.     je    nokey
  200.        ; cmp     al,39h      ; SPACE
  201.        ; je     nokey
  202.  
  203.     ;ignore all other keys
  204.         in      al,61h
  205.         mov     ah,al
  206.         or      al,80h
  207.         out     61h,al
  208.         xchg    ah,al
  209.         out     61h,al
  210.         mov     al,20h
  211.         out     20h,al
  212.         pop     ax
  213.     iret
  214.  
  215. nokey:
  216.     pop    ax
  217.         jmp     cs:oldint9
  218. INT9handler ENDP
  219.  
  220. ;-----------------------------------------------------------------
  221. ; SetINT9 - Sets Keyboard Interrupt (9)
  222. ;    IN     : -
  223. ;   OUT     : -
  224. ;  Modified : ax
  225. ;  Vars Used: -
  226.  
  227. SetINT9 PROC NEAR
  228.     cli
  229.     push    es
  230.     xor    ax,ax
  231.     mov    es,ax
  232.     mov    ax,es:[9*4]
  233.     mov    word ptr cs:oldint9[0],ax
  234.     mov    ax,es:[9*4+2]
  235.     mov    word ptr cs:oldint9[2],ax
  236.     mov    ax,offset INT9handler
  237.     mov    es:[9*4],ax
  238.     mov    es:[9*4+2],cs
  239.     pop    es
  240.     sti
  241.     ret
  242. SetINT9 ENDP
  243.  
  244. ;-----------------------------------------------------------------
  245. ; RestoreINT9 - Restores Keyboard Interrupt (9)
  246. ;    IN     : -
  247. ;   OUT     : -
  248. ;  Modified : ax
  249. ;  Vars Used: -
  250.  
  251. RestoreINT9 PROC NEAR
  252.     cli
  253.     push    es
  254.     xor    ax,ax
  255.     mov    es,ax
  256.     mov    ax,word ptr cs:oldint9[0]
  257.     mov    bx,word ptr cs:oldint9[2]
  258.     mov    es:[9*4],ax
  259.     mov    es:[9*4+2],bx
  260.     pop    es
  261.     sti
  262.     ret
  263. RestoreINT9 ENDP
  264.  
  265. ;-----------------------------------------------------------------
  266. ; Waitborder - Wait for next VR
  267. ;    IN     : -
  268. ;   OUT     : -
  269. ;  Modified : -
  270. ;  Vars Used: -
  271.  
  272. Waitborder PROC NEAR
  273.     push    ax
  274.     push    dx
  275.     mov    dx,3dah
  276. wbr1:    in    al,dx
  277.     test    al,8
  278.     jnz    wbr1
  279. wbr2:    in    al,dx
  280.     test    al,8
  281.     jz    wbr2
  282.     pop    dx
  283.     pop    ax
  284.     ret
  285. Waitborder ENDP
  286.  
  287. ;-----------------------------------------------------------------
  288. ; GetRasterline - Gets current rasterline (not exact!) apprx range:1..479
  289. ;    IN     : -
  290. ;   OUT     : ax    (Rasterline)
  291. ;  Modified : cx,dx
  292. ;  Vars Used: frametime
  293.  
  294. GetRasterline PROC NEAR
  295.     ;AX=scan line the VGA is in (requires ints set)
  296.     cli
  297.     xor    al,al
  298.     out    43h,al
  299.     in    al,40h
  300.     mov    dl,al
  301.     in    al,40h
  302.     mov    dh,al
  303.  
  304.     mov    ax,cs:frametime
  305.     sub    ax,dx
  306.     mov    cx,506
  307.     mul    cx
  308.     mov    cx,cs:frametime
  309.     div    cx
  310.     sub    ax,26        ;adjust to 480 (506-26=480)
  311.  
  312.     sti
  313.     ret
  314. GetRasterline ENDP
  315.  
  316. ;-----------------------------------------------------------------
  317. ; WaitRasterline - Wait until Rasterline (not exact!) apprx. range 1..479
  318. ;    IN     : dx    (Rasterline)
  319. ;   OUT     : -
  320. ;  Modified : ax,cx,dx
  321. ;  Vars Used: frametime
  322.  
  323. WaitRasterline PROC NEAR
  324.     ;returns when Scan Line=DX (requires ints set)
  325.     cli
  326.     mov    cx,506          ;# of horizontal scan lines + VR
  327.     mov    ax,480          ;# of horizontal scan lines
  328.     sub    ax,dx
  329.     mul    word ptr cs:frametime
  330.     div    cx
  331.     mov    cx,ax
  332.  
  333. waitraster1:
  334.     xor    al,al
  335.     out    43h,al
  336.     in    al,40h
  337.     mov    ah,al
  338.     in    al,40h
  339.     xchg    al,ah
  340.     cmp    ax,cx
  341.     ja    waitraster1
  342.  
  343.     sti
  344.  
  345.     ret
  346. WaitRasterline ENDP
  347. ;-----------------------------------------------------------------
  348.